package com.example.lib_log.logger

import android.util.Log
import com.example.lib_log.ILogger
import com.example.lib_log.LoggerLevel

/**
 * @author yaotianxue
 * @description 输出到logcat
 * @date 2024/10/21
 */
class LogCatLogger:ILogger {
    private var isDebug = true
    private var TAG = ""
    private var level = LoggerLevel.Debug
    private var loggerFormat = "(:=>$TAG %s -->%s"
    private var url = ""
    
    override fun d(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Debug.value){
            Log.d(TAG, String.format(loggerFormat,tag,log))
        }
    }

    override fun v(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Verbose.value){
            Log.v(TAG, String.format(loggerFormat,tag,log))
        }
    }

    override fun i(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Info.value){
            Log.i(TAG, String.format(loggerFormat,tag,log))
        }
    }

    override fun w(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Warn.value){
            Log.w(TAG, String.format(loggerFormat,tag,log))
        }
    }

    override fun e(tag: String, log: String) {
        if(isDebug && level.ordinal >= LoggerLevel.Error.value){
            Log.e(TAG, String.format(loggerFormat,tag,log))
        }
    }

    override fun setDebug(isDeug: Boolean) {
        this.isDebug = isDeug
    }

    override fun setLogTAG(TAG: String) {
        this.TAG = TAG
    }

    override fun setLoggerLevel(level: LoggerLevel) {
        this.level = level
    }

    override fun setSaveUrl(url: String) {
        this.url = url
    }
}